package com.itheima.health.controller;

import com.itheima.health.dto.CheckGroupDTO;
import com.itheima.health.dto.SetmealDTO;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.service.CheckItemService;
import com.itheima.health.service.SetmealService;
import com.itheima.health.utils.aliyunoss.AliyunUtils;
import com.itheima.health.utils.redis.RedisUtil;
import com.itheima.health.utils.resources.RedisConstant;
import com.itheima.health.utils.resources.UploadUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
//  ordersetting/importOrderSettings
@RestController
@RequestMapping("setmeal")
@Api(tags = "传智健康预约模块之套餐管理")
public class SetmealController {

    @Reference
    private SetmealService setmealService;


    @PostMapping("findPage")
    @ApiOperation(value = "查询功能",notes = "检查项查询列表信息")
    public Result   findPage(@RequestBody QueryPageBean queryPageBean){
        return  new Result(setmealService.findPage(queryPageBean));
    }



    @PostMapping("upload")
    public Result   upload(@RequestParam("imgFile")MultipartFile file) throws IOException {
        String originalFilename = file.getOriginalFilename(); //  文件真实名称
        String  uuidFilename = UploadUtils.generateRandonFileName(originalFilename);
        //  上传 oss 上
        AliyunUtils.uploadMultiPartFileToAliyun(file.getBytes(),uuidFilename);
        //  图片 存储 set  并且设置过期时间
        RedisUtil.addToSet(RedisConstant.ALL_SETMEAL_PIC_SET,uuidFilename);
        RedisUtil.set(RedisConstant.SINGLE_PIC+uuidFilename,uuidFilename,30,TimeUnit.SECONDS);
        return  new Result(uuidFilename);
    }

    @PostMapping("save")
    public Result   save(@RequestBody SetmealDTO setmealDTO){
        return  new Result(setmealService.saveSetmeal(setmealDTO));
    }







}
